#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int NN=5e5+4;
int q[NN],s[NN],n;
pair<ll,int>tr[NN],ans[NN];
vector<pair<int,int> >p[NN];
pair<ll,int>check(pair<ll,int>a,pair<ll,int>b)
{
	if((__int128)a.first*b.second<(__int128)b.first*a.second)
		return b;
	return a;
}
int lowbit(int x)
{
	return x&-x;
}
void add(int u,pair<ll,int>w)
{
	while(u)
	{
		tr[u]=check(tr[u],w);
		u-=lowbit(u);
	}
}
pair<ll,int>ask(int u)
{
	pair<ll,int>res={0,1};
	while(u<=n)
	{
		res=check(res,tr[u]);
		u+=lowbit(u);
	}
	return res;
}
void solve()
{
	int head=0,tail=0;
	q[0]=0;
	for(int i=1;i<=n;i++)
	{
		while(head<=tail&&s[q[tail]]>=s[i])
			tail--;
		for(int j=head;j<=tail;j++)
			add(q[j]+1,{1ll*(s[i]-s[q[j]])*(s[i]-s[q[j]]),i-q[j]});
		for(int j=0;j<p[i].size();j++)
			ans[p[i][j].second]=check(ans[p[i][j].second],ask(p[i][j].first));
		q[++tail]=i;
	}
}
pair<ll,int>solve2(int l,int r)
{
	int head=0,tail=0;
	q[0]=l-1;
	pair<ll,int>res={0,1};
	for(int i=l;i<=r;i++)
	{
		while(head<=tail&&s[q[tail]]>=s[i])
			tail--;
		for(int j=head;j<=tail;j++)
			res=check(res,{1ll*(s[i]-s[q[j]])*(s[i]-s[q[j]]),i-q[j]});
		q[++tail]=i;
	}
	return res;
}
int main()
{
	freopen("value.in","r",stdin);
	freopen("value.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
		s[i]+=s[i-1];
		tr[i]={0,1};
	}
	int m;
	scanf("%d",&m);
	if(m==1)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		pair<ll,int>t=solve2(l,r);
		for(int i=1;i<=n;i++)
			s[i]=-s[i];
		t=check(t,solve2(l,r));
		ll g=__gcd(t.first,1ll*t.second);
		printf("%lld %lld\n",t.first/g,t.second/g);
		return 0;
	}
	for(int i=1;i<=m;i++)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		ans[i]={0,1};
		p[r].push_back({l,i});
	}
	solve();
	for(int i=1;i<=n;i++)
		s[i]=-s[i],tr[i]={0,1};
	solve();
	for(int i=1;i<=m;i++)
	{
		ll g=__gcd(ans[i].first,1ll*ans[i].second);
		printf("%lld %lld\n",ans[i].first/g,ans[i].second/g);
	}
	return 0;
}
